package com.aoxin.util;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.aoxin.mapper.course.webCourse.SlfChildrenMapper;
import com.aoxin.model.course.SlfChildren;
import com.aoxin.util.ageUtils.ChildrenAgeUtil;
/**
 * 定时更新用户孩子年龄
 * @author Administrator
 *
 */
@EnableScheduling
@Component
public class ChildrenAgeToUpdate {
	@Autowired
	SlfChildrenMapper slfChildrenMapper;
	
	@Scheduled(cron = "0 0 3 * * ?") 
	private void UpdateChildrenAge(){
		//每日凌晨3点更新
		System.out.println("----------------------- 定时更新children start--------------------------------");
		SlfChildren slfchildren=new SlfChildren();
		List<SlfChildren> listChildren=slfChildrenMapper.getChildren(slfchildren);
		for (SlfChildren slfChildrenValue : listChildren) {
			String childrenAge=ChildrenAgeUtil.getAge(slfChildrenValue.getBirthday());
			slfchildren.setAge(childrenAge);
			slfchildren.setUserId(slfChildrenValue.getUserId());
			slfchildren.setChildrenId(slfChildrenValue.getChildrenId());
			slfChildrenMapper.updateChildren(slfchildren);
		}
		
		System.out.println("----------------------- 定时更新children end--------------------------------");
		
		
	}
}
